package net.csdn.business.auth.feign;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.csdn.business.auth.service.PersonTokenService;
import net.csdn.business.common.annotation.Inner;
import net.csdn.business.common.domain.request.oauth.PersonalAccessTokenDTO;
import net.csdn.business.common.domain.request.oauth.PersonalAccessTokenQuery;
import net.csdn.business.common.domain.request.oauth.RevokedPersonTokenDTO;
import net.csdn.business.common.domain.vo.oauth.OauthTokenInfoVO;
import net.csdn.business.common.domain.vo.oauth.PersonalAccessTokenVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * @Desc: Tokencontroller
 * @ClassName: TokenController
 * @Author: yourleige@163.com
 * @Date: 2022/9/27 11:16
 */
@Slf4j
@Inner
@RestController
@RequestMapping("/api/v1/personalToken")
@RequiredArgsConstructor
public class AuthPersonController
{
    private final PersonTokenService personTokenService;



    /**
     * @Desc: 分页查询私人token
     * @Author: zhangyalei
     * @Date: 2022/12/19 17:44
     */
    @PostMapping("/list")
    public Page<PersonalAccessTokenVO> findPageList(@RequestBody PersonalAccessTokenQuery params){
        return personTokenService.findPageList(params);
    }


    /**
     * @Desc: 新增私人token
     * @Author: zhangyalei
     * @Date: 2022/12/19 17:44
     */
    @PostMapping("/add")
    public PersonalAccessTokenVO addPersonalAccess(@Validated @RequestBody PersonalAccessTokenDTO params){
        return personTokenService.addPersonalAccess(params);
    }



    /**
     * @Desc: 根据id撤销私人token
     * @Author: zhangyalei
     * @Date: 2022/12/19 17:44
     */
    @PostMapping("/revoked")
    public Integer revokedPersonToken(@Validated @RequestBody RevokedPersonTokenDTO params){
        return personTokenService.revokedPersonToken(params);
    }


    /**
     * @Desc: 根据userId撤销本人所有私人token
     * @Author: zhangyalei
     * @Date: 2022/12/19 17:44
     */
    @PostMapping("/revokedAll")
    public Integer revokedAllPersonToken(@Validated @RequestBody RevokedPersonTokenDTO params){
        return personTokenService.revokedAllPersonToken(params);
    }

    /**
     * @Desc: 根据token获取token包含的用户信息、以及scope
     * @Author: zhangyalei
     * @Date: 2023/03/16 17:00
     */
    @GetMapping("/getInfo")
    public OauthTokenInfoVO getInfo(@RequestParam("token")String token){
        return personTokenService.getInfo(token);
    }
}
